import {
  fileURLToPath,
  URL
} from 'node:url'
import {
  defineConfig
} from 'vite'
//element-plus配置
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  ElementPlusResolver
} from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  // define: {
  //   'process.env.VITE_APP_PLATFORM': '"pc"' // 或 'pc'
  // },
  plugins: [
    vue(),
    vueDevTools(),
    //element-plus配置
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src',
        import.meta.url))
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        // target: 'http://localdemo:8080',
        // target: 'http://localdemo.com',
        secure: false,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
